package com.topcoder.srm528;

import java.util.Arrays;

public class Mosquitoes {
	public int getMaximum(int[] xInit, int[] v, int R) {
		int N = v.length;
		int max = 1;
		
		double[] list = new double[N];
		for (int i=0; i<N-1; i++) {
			for (int j=i+1; j<N; j++) {
				double t = v[i]==v[j]? 0 : 1.0 * (xInit[j] - xInit[i])/(v[i] - v[j]);
				if (t < 0) t = 0;
				
				for (int k=0; k<N; k++) list[k] = xInit[k] + t*v[k];
				Arrays.sort(list);
				
				int nextK = 0;
				for (int k=0; k<N; k++) {
					double next = list[k] + 2*R;
					while (nextK<N && list[nextK] <= next + 1E-9) nextK++;
					
					max = Math.max(max, nextK - k);
				}
			}
		}
		
		return max;
	}
}
